package com.example.graduatetest.fragments;


import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.graduatetest.R;
import com.example.graduatetest.databinding.FragmentNoticeBinding;
import com.example.graduatetest.view.model.NoticeViewModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class NoticeFragment extends Fragment {

    private NoticeViewModel noticeViewModel;
    private FragmentNoticeBinding binding;

    public NoticeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        if(noticeViewModel == null){
            noticeViewModel = new NoticeViewModel();
        }
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_notice, container, false);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        noticeViewModel = ViewModelProviders.of(requireActivity()).get(NoticeViewModel.class);

        binding.setNoticeViewModel(noticeViewModel);
        binding.setLifecycleOwner(this);
        noticeViewModel.init(requireActivity(),binding);
    }
}
